package cc.fengz.utils;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import org.apache.commons.lang.StringUtils;

public class UrlUtils {
	
	/**
	 * 取根路径
	 * @param url
	 * @return
	 */
	public static String getRoot(URL url){
		String path = url.toString() ;
		return StringUtils.removeEnd(path, url.getPath()) ;
	}
	

	public static String getRoot(StringBuffer requestURL) {
		URL url;
		try {
			url = new URL(requestURL.toString());
		} catch (MalformedURLException e) {
			e.printStackTrace();
			return "" ;
		}
		return getRoot(url);
	}
	
	public static void main(String[] args) throws IOException {
		URL url = new URL("http://192.168.31.54:8080/FileManage/Upload") ; 
		
	
		
		System.out.println(UrlUtils.getRoot(url));
	}


}
